package com.hziee.cosmanage.member.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration
@EnableSwagger2 //开启swagger2
public class SwaggerConfig {


//    @Bean
//    public Docket docket1(){
//        return new Docket(DocumentationType.SWAGGER_2).groupName("A");
//    }


    //配置了Swagger的Docket的Bean实例
    @Bean
    public Docket docket(Environment environment){

        //设置要显示swagger的环境
        Profiles profiles = Profiles.of("dev");

        //获取项目环境：判断是否处在自己设定的环境当中
        boolean flag = environment.acceptsProfiles(profiles);

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("member")
                //是否启用Swagger
                .enable(true)
                .select()
                //RequestHandlerSelectors配置扫描接口的方式
                .apis(RequestHandlerSelectors.basePackage("com.hziee.cosmanage.member.controller"))
                //paths过滤什么路径
                //.paths(PathSelectors.ant("/kuang/**"))
                .build();
    }

    //配置Swagger信息=apiInfo
    private ApiInfo apiInfo(){

        Contact contact = new Contact("杨斌","https://www.baidu.com/","1213660473@qq.com");

        return new ApiInfo(
                "用户模块",
                "跨人才组织系统的用户的API文档",
                "1.0",
                "https://www.baidu.com/",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList()
        );
    }

}
